<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@page import="com.yaodian100.core.common.utils.PasswordUtils"%>
<%@page import="java.util.Date"%>
<%@page import="org.apache.commons.lang.StringUtils"%>
<%@page import="com.yaodian100.ec.member.service.MemberService"%>
<html>
<head>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="0"> 
<script language="javascript">
	$().ready(function(){
		$("#pwdTip").hide();
		$("#rcpwdTip").hide();

		$("#submit_data").click(function(){
			var isCorrect = true;
			
			//clear tips
			$("#pwdTip").hide();
			$("#rcpwdTip").hide();
			
			var text = $("#pwd").attr('value');
			if(text.length==0){
				$("#pwdTip").html("请输入新密码");
				$("#pwdTip").show();
				isCorrect = false;
			}else if(text.length<6||text.length>16){
				$("#pwdTip").html("密码长度只能在6-16位字符之间");
				$("#pwdTip").show();
				isCorrect = false;
			}else if(text.indexOf(' ')>=0){
				$("#pwdTip").html("密码不能含有空白");
				$("#pwdTip").show();
				isCorrect = false;
			}else if(text.match(/[^a-zA-Z0-9]/g)){
				$("#pwdTip").html("只能使用大小写英文字母、数字");
				$("#pwdTip").show();
				isCorrect = false;
			}
			
			if($("#rcpwd").attr('value')!=text){
				$("#rcpwdTip").html("两次密码不同");
				$("#rcpwdTip").show();
				isCorrect = false;
			}
			
			if(isCorrect){
				$("#modifypwdForm").submit();
				return false;
			}
		});
	});
</script>
</head>
<body>
<%
String code;
String[] token = new String[2];
if(StringUtils.isNotBlank((String)request.getAttribute("actionResult"))){
	code = null;
}else{
	String loginID = (String)request.getAttribute("loginID");
	String ccode = (String)request.getAttribute("ccode");
	code = request.getParameter("id");
	if(StringUtils.isNotBlank(loginID)){
		code = loginID;
		token[0] = loginID;
		token[1] = ccode;
	}else{
		if(code != null){
			try{
				code = PasswordUtils.decodePassword(code, null);
				token = code.split("-");
				MemberService memberService = (MemberService)request.getAttribute("memberService");
				if(!memberService.getMemberByLoginId(token[0]).getForgetPwdToken().equals(token[1])){
					code = null;
				}
			}catch(Exception e){
				code = null;
			}
		}
	}
}
%>
  <div id="main" class="member-reg m-changepwd">
  	<h3>重设密码</h3>
  	<% if(code == null){%>
  		<p class="pointmsg">连结無效。</p>
  	<% }else if((token[1].length()!=8)&&(new Date().getTime()-Long.parseLong(token[token.length-1]))/1000>86400){ %>
  		<p class="pointmsg">连结已失效。</p>
  	<% }else{ %>
  	<s:form action="forgetpwdchanged.do" method="post" id="modifypwdForm">
    <div class="m-regform">
     <p class="pointmsg">为保护您的帐号安全，请立即重设您的新的密码。</p>
   	   <ul>
         <li><div><label>新密码：</label></div><div><input type="password" name="pwd" id="pwd" size="20" /> <span class="txt-gy">密码可由大小写英文字母、数字组成，长度6－16个字符。</span><br /><span id="pwdTip" class="msg rn">请输入密码</span></div></li>
         <li><div><label>再次输入新密码：</label></div><div><input type="password" name="rcpwd" id="rcpwd" size="20" /> <br /><span id="rcpwdTip" class="msg rn">两次密码不同</span></div></li>
   	   </ul>
   	   <input type="hidden" name="loginID" value="<%=token[0]%>" />
   	   <input type="hidden" name="ccode" value="<%=token[1]%>" />
       <p align="center"><a href="javascript:;" id="submit_data" class="btn-mid">提交</a><br />
         <br /></p>
     </div>
	</s:form>
    <div class="tips-li">
       <strong>安全密码提示：</strong>

          <ul>
            <li>．请勿使用之前用过的相同密码。</li>
            <li>．请勿使用单词、您的姓名、电子邮件地址或其他容易获取的个人信息。</li>
            <li>．请勿为多个在线帐户使用同一密码。 </li>
          </ul>
     </div>
	<% } %>
  </div>
</body>
</html>